package com.example.demo.ai.llm.service;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import org.noear.solon.ai.rag.Document;
import org.noear.solon.ai.rag.repository.RedisRepository;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;

/**
 * @author airhead
 */
@Component
public class RepositoryService {
  @Inject RedisRepository repository;

  public Boolean addDoc(String content) {
    try {
      Document document = new Document(content);
      repository.insert(Collections.singletonList(document));
      return true;
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

  public List<String> search(String query) {
    try {
      List<Document> list = repository.search(query);
      return list.stream().map(Document::getContent).toList();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

  public String history() {
    return "无其他慢性病";
  }
}
